import { createRouter, createWebHashHistory } from 'vue-router'
import LoginView from '@/views/LoginView.vue'
import HomeView from '@/views/HomeView.vue'
import login from '@/views/Product/List.vue'

const routes = [
  {
    path: '/',
    component: LoginView
  },
  // {
  //   path: '/home',
  //   name:"index",
  //   component: () => import('@/views/HomeView.vue'),
  //   children:[
  //     {
  //       path: '',
  //   name:"home",
  //   component: () => import('@/components/HelloWorld.vue'),
  //     }
  //     ]
  // },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children: [
      {
        path: '/',
        name: 'main',
        component: () => import("@/views/Product/List.vue"),
      },

      // 商品管理
      // 商品列表
      {
        path: '/list',
        name: 'list',
        component: () => import("@/views/Product/List.vue"),
      },
      // 商品发布
      {
        path: '/AddProduct',
        name: 'AddProduct',
        component: () => import('@/views/Product/AddProduct.vue')
      },
      // 商品分类
      {
        path: '/Classify',
        name: 'Classify',
        component: () => import('@/views/Product/Classify.vue')
      },
      // 添加商品分类
      {
        path: '/addCategory',
        name: 'addCategory',
        component: () => import('@/views/Product/AddCategory.vue')
      },
      // 订单管理
      // 交易订单
      {
        path: '/Trans',
        name: 'Trans',
        component: () => import('@/views/Order/Trans.vue')
      },
      // 维权订单
      {
        path: '/Rights',
        name: 'Rights',
        component: () => import('@/views/Order/Rights.vue')
      },
      // 评价管理
      {
        path: '/Evaluation',
        name: 'Evaluation',
        component: () => import('@/views/Order/Evaluation.vue')
      },
      // 用户管理
      // 用户列表
      {
        path: '/Listx',
        name: 'Listx',
        component: () => import('@/views/User/List.vue')
      },
      // 用户详情
      {
        path: '/Detail',
        name: 'Detail',
        component: () => import('@/views/User/Detail.vue')
      },
      // 分销商
      // 分销商列表
      {
        path: '/Listy',
        name: 'Listy',
        component: () => import('@/views/Distributor-C/List.vue')
      },
      // 分销商详情
      {
        path: '/details',
        name: 'details',
        component: () => import('@/views/Distributor-C/details.vue')
      },
      //下线列表
      {
        path: '/OffineList',
        name: 'OffineList',
        component: () => import('@/views/Distributor-C/OffineList.vue')
      },
      //分销商等级
      {
        path: '/Grade',
        name: 'Grade',
        component: () => import('@/views/Distributor-C/Grade.vue')
      },
      //添加等级
      {
        path: '/AddClassify',
        name: 'AddClassify',
        component: () => import('@/views/Distributor-C/AddClassify.vue')
      },
      //分销商品
      {
        path: '/Product',
        name: 'Product',
        component: () => import('@/views/Distributor-C/Product.vue')
      },
      //分销订单
      {
        path: '/Order',
        name: 'Order',
        component: () => import('@/views/Distributor-W/Order.vue')
      },
      //提现管理
      {
        path: '/CashOut',
        name: 'CashOut',
        component: () => import('@/views/Distributor-W/CashOut.vue')
      },
      //素材中心
      {
        path: '/Source',
        name: 'Source',
        component: () => import('@/views/Distributor-W/Source.vue')
      },
      //分销设置
      {
        path: '/Setting',
        name: 'Setting',
        component: () => import('@/views/Distributor-W/Setting.vue')
      },
      //佣金结算
      {
        path: '/Settlement',
        name: 'Settlement',
        component: () => import('@/views/Distributor-W/Settlement.vue')
      },
      //设置
      {
        path: '/BaseSetting',
        name: 'BaseSetting',
        component: () => import('@/views/Setting/BaseSetting.vue')
      },
    ]
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 挂在路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // 访问登录页面 直接放行
  if (to.path === '/') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  // 没有token， 强制转到login页面
  if (!tokenStr) return next('/login')
  next()
})

export default router 